﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.Windows.Forms;
using System.Drawing.Printing;

namespace MisClient
{
    public class FrmPrint
    {
        private string _Title = "";                                         //标题

        public string Title
        {
            get { return _Title; }
            set { _Title = value; }
        }
        private Font _TitleFont = new Font("宋体", 20, FontStyle.Bold);     //字体样式标题

        public Font TitleFont
        {
            get { return _TitleFont; }
            set { _TitleFont = value; }
        }
        private Point _CurrentPoint = new Point(30, 30);                    //起初坐标

        public Point CurrentPoint
        {
            get { return _CurrentPoint; }
            set { _CurrentPoint = value; }
        }
        private string _Content = "";                                       //内容

        public string Content
        {
            get { return _Content; }
            set { _Content = value; }
        }
        private Font _ContentFont = new Font("宋体", 12);                   //内容字体样式

        public Font ContentFont
        {
            get { return _ContentFont; }
            set { _ContentFont = value; }
        }
        private Boolean _HasMorePages = false;

        public Boolean HasMorePages
        {
            get { return _HasMorePages; }
            set { _HasMorePages = value; }
        }

        private PrintDocument printDocument = new PrintDocument();
        private PrintPreviewDialog printPreviewDialog = new PrintPreviewDialog();

        public FrmPrint()
        {
            
            printDocument.PrintPage += new PrintPageEventHandler(this.winPrintPage);
        }

        public void winPrint(string _Title, string _Content,Boolean _HasMorePages)
        {
            this._Title = _Title;
            this._Content = _Content;
            this._HasMorePages = _HasMorePages;
            this.printPreviewDialog.Document=this.printDocument;
            this.printPreviewDialog.PrintPreviewControl.Zoom = 1.0;
            this.printPreviewDialog.ShowDialog();

           
        }

        private void winPrintPage(object sender, System.Drawing.Printing.PrintPageEventArgs e)
        {
            e.HasMorePages = this._HasMorePages;
            if (null != this._Title && !"".Equals(this._Title))
            {
                this._CurrentPoint.X = (e.PageBounds.Width) / 2 - (int)(e.Graphics.MeasureString(_Title, _TitleFont).Width) / 2;
                e.Graphics.DrawString(_Title, _TitleFont, new SolidBrush(Color.Black), _CurrentPoint);
            }
            this._CurrentPoint.X = 30;
            this._CurrentPoint.Y += (int)(e.Graphics.MeasureString(_Title, _TitleFont).Height) + 50;
            e.Graphics.DrawString(this._Content, _ContentFont, new SolidBrush(Color.Black), _CurrentPoint);
        }
    }
}
